import {
  api as Api,
  BASE_URL
} from '../js/api.js';
import {
  defineStore
} from 'pinia';

const store = defineStore('user', {
  state() {
    return {
      islogin: false,
      userinfo: {
        tbUser: {},
        tbUserInfo: {},
        tbRole: {},
        exInfo: {},
      },
    };
  },
  actions: {
    queryUser(cb) {
      let instance = this;
      Api.get('/auth', {}, (data) => {
        if (data.success) {
          instance.islogin = true;
          instance.userinfo = data.data;
        } else {
          instance.islogin = false;
          instance.userinfo = {
            tbUser: {},
            tbUserInfo: {},
            tbRole: {},
            exInfo: {},
          };
        }
        cb?.(data.success);
      });
    },
  },
});

export default store;